package own.stu.jobgib.playown.dp.principle.isp.service;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledUpdater {

    private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();

    private long initialDelayInSec;

    private long preiodInSec;

    private Updater updater;

    public ScheduledUpdater(long initialDelayInSec, long preiodInSec, Updater updater) {
        this.initialDelayInSec = initialDelayInSec;
        this.preiodInSec = preiodInSec;
        this.updater = updater;
    }

    public void run() {
        executorService.scheduleAtFixedRate(() -> {
            updater.update();
        }, this.initialDelayInSec, this.preiodInSec, TimeUnit.SECONDS);
    }

}
